﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.LIB;

namespace YArchitech.Plumbing.ParamForm
{
	public partial class SystemSettingForm : System.Windows.Forms.Form
	{
		public SystemSettingForm(OptionData option)
		{
			this.InitializeComponent();
			base.Icon = Resource.YArchitechIcon;
			this.option = option;
		}

		private void SystemSettingForm_Load(object sender, EventArgs e)
		{
			this.cbxKeyPipe.Items.AddRange(new object[]
			{
				"同程",
				"异程"
			});
			this.cbxRiserPipe.Items.AddRange(new object[]
			{
				"同程",
				"异程"
			});
			this.LoadData();
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			if (this.hyTxtReturnTem.Text == "" || this.hyTxtSupplyTem.Text == "")
			{
				YJKMessageBox.Information("参数不能为空。");
				return;
			}
			if (double.Parse(this.hyTxtReturnTem.Text) >= double.Parse(this.hyTxtSupplyTem.Text))
			{
				YJKMessageBox.Information("供水温度应大于回水温度。");
				return;
			}
			this.SaveData();
			base.DialogResult = DialogResult.OK;
		}

		private void LoadData()
		{
			this.cbxKeyPipe.SelectedIndex = this.option.MainPipeInter - 1;
			this.cbxRiserPipe.SelectedIndex = this.option.RiserPipeInter - 1;
			this.hyTxtSupplyTem.Text = this.option.TemperSupply.ToString();
			this.hyTxtReturnTem.Text = this.option.TemperReturn.ToString();
		}

		private void SaveData()
		{
			this.option.MainPipeInter = this.cbxKeyPipe.SelectedIndex + 1;
			this.option.RiserPipeInter = this.cbxRiserPipe.SelectedIndex + 1;
			this.option.TemperSupply = double.Parse(this.hyTxtSupplyTem.Text);
			this.option.TemperReturn = double.Parse(this.hyTxtReturnTem.Text);
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private OptionData option;
	}
}
